//
//  NSObjectExt.swift
//  test-ios
//
//  Created by wyz5204 on 2023/6/6.
//

import Foundation
import UIKit
import Toast_Swift

extension NSObject {
    /// 当前的 控制器
    func currentViewController() -> UIViewController {
        var VC = SceneDelegate.shared.window?.rootViewController
        if VC is UITabBarController {
            let sVC = VC as! UITabBarController
            VC = sVC.selectedViewController
        }
        
        if VC is UINavigationController {
            let nVC = VC as! UINavigationController
            VC = nVC.visibleViewController
        }
        return VC ?? UIViewController()
    }
    
    /// 当前的View
    func currentView() -> UIView {
        return currentViewController().view
    }
    
    func showLoading() {
        currentView().makeToastActivity(.center)
    }
    func showToast(_ message: String?) {
        currentView().hideToastActivity()
        currentView().hideAllToasts()
        currentView().makeToast(message, duration: 2.0, position: .center)
    }
    
    func hideLoading() {
        currentView().hideToastActivity()
    }
    
    
}
